﻿#include "stdafx.h"
#include "ImageTaskFactory.h"
//基本
#include "ErosionTask.h"
#include "DilationTask.h"
#include "OpeningTask.h"
#include "ClosingTask.h"
#include "ThresholdTask.h"
#include "GrayscaleTask.h"
//滤波
#include "GaussianBlurTask.h"

// 映射 TaskType 枚举到显示名称
const std::map<TaskType, QString> ImageTaskFactory:: taskTypeNames = {
			{TaskType::Erosion, "腐蚀"}, {TaskType::Dilation, "膨胀"},
			{TaskType::Opening, "开运算"}, {TaskType::Closing, "闭运算"},
			{TaskType::GaussianBlur, "高斯模糊"}, {TaskType::MedianBlur, "中值滤波"},
			{TaskType::BilateralFilter, "双边滤波"},
			{TaskType::Canny, "Canny 边缘检测"}, {TaskType::Sobel, "Sobel 边缘检测"},
			{TaskType::Threshold, "二值化"},{TaskType::Grayscale, "灰度化"},
			{TaskType::Rotate, "旋转"}, {TaskType::Scale, "缩放"}, {TaskType::Translate, "平移"},
			{TaskType::ColorConversion, "颜色空间转换"}, {TaskType::HistogramEqualization, "直方图均衡化"}
};


// 定义分组和任务的映射表
const std::map<std::string, std::vector<TaskType>> ImageTaskFactory::taskGroups = {
	{"基本操作", {TaskType::Erosion, TaskType::Dilation, TaskType::Opening, TaskType::Closing,TaskType::Threshold,TaskType::Grayscale}},
	{"滤波操作", {TaskType::GaussianBlur, TaskType::MedianBlur, TaskType::BilateralFilter}},
	{"边缘检测", {TaskType::Canny, TaskType::Sobel}},
	{"几何变换", {TaskType::Rotate, TaskType::Scale, TaskType::Translate}},
	{"其他操作", {TaskType::ColorConversion, TaskType::HistogramEqualization}}
};


std::unique_ptr<ImageTask> ImageTaskFactory::createTask(TaskType type)
{
	switch (type) {
	case TaskType::Erosion:
		return std::make_unique<ErosionTask>();
	case TaskType::Dilation:
		return std::make_unique<DilationTask>();
	case TaskType::Opening:
		return std::make_unique<OpeningTask>();
	case TaskType::Closing:
		return std::make_unique<ClosingTask>();
	case TaskType::Threshold:
		return std::make_unique<ThresholdTask>();
	case TaskType::Grayscale:
		return std::make_unique<GrayscaleTask>();
		// 添加新任务类型时在此处扩展
	case TaskType::GaussianBlur:
		return std::make_unique<GaussianBlurTask>();
		// 添加新任务类型时在此处扩展
	default:
		return nullptr; // 未知类型返回空指针
	}
}
